
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[ReportBaseObjectSelectAll]
    @BookmarkId INT ,
    @IsGroup BIT ,
    @OnlyVisible BIT
AS 
    BEGIN
        SELECT  Id ,
                Name ,
                WordBookmarkId ,
                BookmarkGroupId ,
                DateCreated ,
                Visible
        FROM    ReportBaseObject
        WHERE   ( @OnlyVisible = 0
                  AND ( ( @IsGroup = 0
                          AND WordBookmarkId = @BookmarkId
                        )
                        OR ( @IsGroup = 1
                             AND BookmarkGroupId = @BookmarkId
                           )
                      )
                  AND Deleted = 0
                )
                OR ( @OnlyVisible = 1
                     AND ( ( @IsGroup = 0
                             AND WordBookmarkId = @BookmarkId
                           )
                           OR ( @IsGroup = 1
                                AND BookmarkGroupId = @BookmarkId
                              )
                         )
                     AND Visible = 1
                     AND Deleted = 0
                   )
        ORDER BY Name ;
    END
GO
